<?php

namespace app\index\traits;

use app\common\model\Member;
use think\exception\ValidateException;

/**
 * 禁言
 * Trait MutedTrait
 * @package app\member\traits
 */
trait MutedTrait
{

    /**
     * 检查是否被禁言
     * @param Member $member
     * @return void
     */
    private function checkMuted(Member $member): void
    {
        if ($member->muted != 1) {
            return;
        }

        if ($member->mutedLength == 5) {
            throw new ValidateException('由于您的违规操作，您的账号已被永久禁言');
        }

        if ($member->mutedTime > time()) {
            throw new ValidateException('由于您的违规操作，您的账号已被禁言至' . date('Y年n月j日 H点', $member->mutedTime));
        }
    }
}